package GPU2D 
{
	import flash.geom.Point;
	import starling.display.Image;
	import starling.display.Quad;
	import starling.display.QuadBatch;
	import starling.display.Sprite;
	import starling.events.EnterFrameEvent;
	import starling.events.Event;
	import starling.events.Touch;
	import starling.events.TouchEvent;
	import starling.events.TouchPhase;
	import starling.text.TextField;
	import starling.textures.Texture;
	import starling.utils.deg2rad;
	
	
	public class StarlingFirst extends Sprite
	{
		public var quad:Quad;
		
		//[Embed(source="../../bin/starling.jpg")]
		[Embed(source="../../bin/texture/iscript.png")]
		private var starlingPNG:Class;
		private var img:Image 
		public function StarlingFirst() 
		{
			
			addEventListener(Event.ADDED_TO_STAGE,addToStage)
			
			
		}
		
		private function addToStage(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, addToStage);
			var s:Sprite = new Sprite();
			s.x = 100;
			s.y = 100;
			addChild(s)
			
			 quad = new Quad(200, 200,0x66808080,false);
			   // quad.x = 100;
				//quad.y = 100;
			    quad.color = 0xF75000;
				s.addChild(quad)
				
			var tf:TextField = new TextField(100, 20, "Hello Starling!", "Arial", 14, 0xFFFFFF);
			//tf = new TextField(200,100,"welcome to starling framework");
			//tf.x = 100;
			//tf.y = -100/2+10;
			s.addChild(tf);
			s.pivotX = s.width >> 1; 
			s.pivotY = s.height >> 1; 
			s.x = (stage.stageWidth - s.width >> 1 ) + (s.width >> 1); 
			s.y = (stage.stageHeight - s.height >> 1) + (s.height >> 1);
			//s.pivotX = 400;
			//s.pivotY = 300;
			//s.pivotX = 800;
			//s.pivotY = 600;
			
			
			img = new Image(Texture.fromBitmap(new starlingPNG()))
			img.x = 200;
			img.y = 200;
			//img.width = 100;
			//img.height = 50;
			//img.skewY = deg2rad( -10);
			img.addEventListener(TouchEvent.TOUCH,imgTouchLogic)
			addChild(img);
			s.addEventListener(EnterFrameEvent.ENTER_FRAME, update);
		}
		
		private function imgTouchLogic(e:TouchEvent):void 
		{
			var touch:Touch = e.getTouch(stage);
			var pos:Point = touch.getLocation(stage);
			if (touch.phase == TouchPhase.ENDED) {
				trace(e)
				}
			//trace(e.);
		}
		
		private function update(e:EnterFrameEvent):void 
		{
			//img.y --;;
			Sprite(e.currentTarget).rotation += 0.1;
		}
		
	}

}